<?php

class Common_DataTable_Summary_Custom extends Common_DataTable_Summary_Abstract {

    private $str_group_key = null;
    private $arr_values = array();
    
    public function __construct($arr_values = array(), $str_group_key = null) {
        parent::__construct();
        $this->setValues($arr_values);
        $this->setGroupKey($str_group_key);
    }

    public function setValues($arr_values) {
        if(is_array($arr_values)) {
            $this->arr_values = $arr_values;
        }
    }
    
    public function getValues() {
        return $this->arr_values;
    }
    
    public function setGroupKey($str_group_key) {
        $this->str_group_key = $str_group_key;
    }
    
    public function getGroupKey() {
        return $this->str_group_key;
    }
    
    protected function isSummaryForFooters() {
        return is_null($this->str_group_key);
    }
    
    public function getData($int_group_count = null) {
        
        $mix_values = null;
        
        if($this->isSummaryForFooters()) {
            $mix_values = $this->getValues();
            $mix_values = $this->applyVariables($mix_values, array(
                '__COUNT__' => $int_group_count
            ));
        }
        
        return $mix_values;
        
    }
    
    public function getDataForGroup($str_group_key, $str_group_label = null, $int_group_count = null) {
        
        $mix_values = null;
        
        if(!$this->isSummaryForFooters() && ($this->getGroupKey() == $str_group_key)) {
            $mix_values = $this->getValues();
            $mix_values = $this->applyVariables($mix_values, array(
                '__GROUP__' => $str_group_label, 
                '__COUNT__' => $int_group_count
            ));
        }
        
        return $mix_values;
        
    }
    
}
